<%--
  Created by IntelliJ IDEA.
  User: Hou
  Date: 2022/5/13
  Time: 16:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <style>
        table{
            border: 1px solid orange;
            width: 1000px;
            margin: 10px auto;
            text-align: center;
            border-collapse: collapse;
        }
        tr{
            border: 1px solid orange;
            height: 50px;
            text-align: center;
        }
        td,th{
            border: 1px solid orange;
        }
        h2{
            text-align: center;
        }
    </style>
</head>
<body>
<h2>图书列表</h2>

<a href="addBook.jsp">添加图书</a>
<br>

<br>
<p>欢迎 【${uname}】</p>
<table>
    <tr>
        <th>编号</th>
        <th>书名</th>
        <th>价格</th>
        <th>简介</th>
        <th>作者</th>
        <th>出版社</th>
        <th>操作</th>
    </tr>
<%--    展示域中的数据--%>
    <c:forEach items="${bookList}" var="book">
        <tr>
            <td>${book.id}</td>
            <td>${book.name}</td>
            <td>${book.price}</td>
            <td>${book.description}</td>
            <td>${book.author}</td>
            <td>${book.publisher}</td>
<%--    如果return true，那么会访问 链接，如果返回false，会阻断访问链接        --%>
            <td><a href="deleteBook?bookId=${book.id}" onclick="return confirm('确定删除？')">删除</a>&nbsp;&nbsp;&nbsp;<a href="toUpdate?bookId=${book.id}">修改</a></td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="7">

            <!--  pageContext.request.contextPath可以获取到 http://localhost:8080/bookList-->
            <a href="<c:url  value='/bookList?pageIndex=1'></c:url> ">首页</a>

            <!--如果当前在第一页, 不能点击上一页-->
            <c:if test="${page.pageIndex > 1}">
                <a href="<c:url  value='/bookList?pageIndex=${page.pageIndex - 1}'></c:url> ">上一页</a>
            </c:if>

            <!--点击下一页, 需要判断, 当前页一定小于总页数-->
            <c:if test="${page.pageIndex < page.totalPages}">
                <a href="<c:url  value='/bookList?pageIndex=${page.pageIndex + 1}'></c:url>">下一页</a>
            </c:if>

            <!--点击下一页, 判断如果当前页等于总页数, 不允许点击下一页-->
            <c:if test="${page.pageIndex == page.totalPages}">
                <a>下一页</a>
            </c:if>

            <!--尾页 = 最后一页也就是总页数-->
            <a href="<c:url  value='/bookList?pageIndex=${page.totalPages}'></c:url>">尾页</a>

        </td>
    </tr>

</table>
</body>
</html>
